package com.ljx.funchat.chat.controller;


import com.ljx.funchat.chat.domain.vo.req.RedbagObtainReq;
import com.ljx.funchat.chat.domain.vo.req.RedbagSendReq;
import com.ljx.funchat.chat.service.IRedbagService;
import com.ljx.funchat.common.domain.vo.resp.ApiResult;
import com.ljx.funchat.common.utils.RequestHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 红包表 前端控制器
 * </p>
 *
 * @author LiJunXi
 * @since 2024-02-18
 */
@Api(tags = "红包接口")
@RestController
@RequestMapping("/chat/redbag")
public class RedbagController {

    @Autowired
    private IRedbagService redbagService;

    @ApiOperation("发送红包")
    @PostMapping("/send")
    public ApiResult<Void> sendRedBag(@Valid @RequestBody RedbagSendReq req){
        Long uid = RequestHolder.get().getUid();
        redbagService.sendRedBag(uid, req);

        return ApiResult.success();
    }

    @ApiOperation("获取红包验证码")
    @GetMapping("/code")
    public ApiResult<String> redbagCode(){
        Long uid = RequestHolder.get().getUid();

        return ApiResult.success(redbagService.redbagCode(uid));
    }

    @ApiOperation("抢红包")
    @PostMapping("/obtain")
    public ApiResult<Void> obtainRedbag(@Valid @RequestBody RedbagObtainReq req){
        Long uid = RequestHolder.get().getUid();
        redbagService.obtainRedbag(uid, req);

        return ApiResult.success();
    }
}

